9月 7 2017 Online Judge►LeetCode [LeetCode] 513 - Find Bottom Left Tree Value 題意找出樹中最下層且最左邊的元素。 解法BFS。 程式1234567891011121314151617181920212223242526/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } *//** * @param {TreeNode} root * @return {number} */var findBottomLeftValue = function(root) { if ( !root ) return 0; let queue = [root]; let result = 0; while( queue.length !== 0 ){ let length = queue.length; for ( let i = 0; i < length; i ++ ){ let node = queue.shift(); if ( i === 0 ) result = node.val; if ( node.left ) queue.push(node.left); if ( node.right ) queue.push(node.right); } } return result;}; Newer [LeetCode] 508 - Most Frequent Subtree Sum Older [LeetCode] 515 - Find Largest Value in Each Tree Row